Software programming source code must be written in a precise syntax so that the compiler or interpreter can correctly convert the source code to machine code. When there are errors in the syntax of the source code, the compiler/interpreter cannot convert the source code to machine code, or converts the source code in a manner that was not intended by the author of the source code. For a novice, learning the correct syntax of a software programming language is burdensome and time consuming. Even for an experienced programmer, learning the correct syntax for a function of which the programmer is not yet familiar is time consuming. For example, the programmer may need to consult a reference (e.g., a textbook) to find a suitable function and then learn the correct syntax for using the function.
Some programming systems provide a graphical user interface to permit a user to create a program. For example, a user can create a program by spatially arranging and connecting boxes with arrows, and associating textual expressions with the boxes. The textual expressions are in a precise context and define the actions to be taken upon input to a box.
This disclosure will refer to example implementations in the context of the MATHEMATICA® computational system available from Wolfram Research, Inc. The methods and system described herein are more general and could be implemented in a variety of environments such as in other computational systems and in software development systems (e.g., source code development systems).
MATHEMATICA® is a powerful computational tool that can evaluate general symbolic expressions, as well as mathematical and numeric expressions. A unifying feature of MATHEMATICA® is that everything is internally represented as a symbolic expression, with all more specific data types treated as special cases—symbols to which additional rules apply. MATHEMATICA® is an interpreted language, with a notion of “evaluation” of symbolic expressions. Evaluation consists in applying to any symbolic expression all transformation rules that fit that expression.
In the MATHEMATICA® software system, a user can create interactive electronic documents referred to as “notebooks.” Various expressions, including numeric and symbolic expressions, can be entered into a notebook via a keyboard, for example, and a user can cause the expression to be evaluated. As a simple example, a user could set a variable x to the numeric value 5 by typing “x=5” into the notebook and then pressing “ENTER” while holding down the “SHIFT” key. This is shorthand for the expression Set[x, 5], calling the built in function “Set”.
In response, the MATHEMATICA® software system conceptually sets the abstract variable x to the value 5. The symbolic expression “x” can, when evaluated, be replaced by the symbol 5. This is one technique by which an interpreted symbolic language may implement variables and variable assignments.
Next, the user could type in an expression x2 by typing “x^2” into the notebook. To evaluate this expression, the user could then press “Enter” while holding down the “Shift” key. In response, the MATHEMATICA® software system evaluates x2 based on the current value of x (set by the user to 5) and would then display “25” in the notebook. To have the notebook display the value of x2 for a different value of x, the user could first type into the notebook the new value of x. For example, the user could type “x=7” into the notebook and then pressing “Shift” and “Enter”. In response, the MATHEMATICA® software system resets the variable x to the value 7. Next, the user could retype “x^2” into the notebook and then press “Shift” and “Enter”. Alternatively, instead of retyping “x^2” into the notebook, the user could place a cursor on or next to the previously entered expression “x^2” and then press “Shift” and “Enter”. In response, the MATHEMATICA® software system evaluates x2 based on the new value of x (set by the user to 7) and would then display “49” in the notebook.
If no value has been assigned to a symbol, evaluation will return the symbol itself unchanged. Thus if a user types x^2, holds “shift” and “enter”, without any previous “Set” operation, the MATHEMATICA® software system will return x2. The system knows various rules to apply to compound symbolic expressions (through functions like “Expand” or “Simplify”, for example), whether their component sub-expressions have “Set” values or not.
Spreadsheet software applications, such as the EXCEL® software application available from Microsoft Corporation, permit a user to create spreadsheets comprising grids of cells. In a spreadsheet, a value in one cell may be dependent upon a value in one or more other cells. For example, a user may assign a formula to a first cell that uses a value from a second cell. Then, the spreadsheet application will calculate an output of the formula using the value from the second cell, and will display the calculated value in the first cell. Such applications require inputs to the first cell in a numeric form, need an explicit formula taking numeric input to relate the contents of the second cell to the numeric values in the first, and output numeric output to the second cell.